﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FormControllers;
using Ecopsy.Tools;
using Ecopsy.DataTier;
using AgencyEntityLib.BaseEntity;
using SqlLibrary;
using Ecopsy.DataTier.SqlLibrary;

public partial class iCRM_Calendar : iPageController 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ctlCalendar1.AnchorDay = DateTime.Now;
            DataBind();
            btnFind_Click(null,null);
        }
        ctlCalendar1.OnPeriodChange = ReBind;
        ctlEmpCombo1.OnSelectedIndexChanged = ctlEmpCombo1_OnSelectedIndexChanged;
    }

    protected bool ctlEmpCombo1_OnSelectedIndexChanged(ListItem Item)
    {
        btnFind_Click(null,null);
        return true;
    }
    protected bool ReBind()
    {
        btnDaySet.DataBind();
        btnMonthSet.DataBind();
        btnWeekset.DataBind();
        lblPeriod.DataBind()  ;
        return true;
    }
    protected void Init()
    {
    
    }

    protected bool IsMyCaLendarMode(string sMode)
    {
        return (sMode == ctlCalendar1.PeriodType.ToString());

    }

    protected string PeriodAsString
    {
        get { return ctlCalendar1.PeriodAsString; }
    }

    protected void btnFind_Click(object sender, ImageClickEventArgs e)
    {
        string sFlt = txtSearch.Text;
        int errPosition = -1;
        if (!ExpressionChecker.CheckStatment(ref sFlt, ref errPosition))
        {
            ScriptManager.RegisterStartupScript(this, GetType(), "AlertBadFiltr", "alert('Ошибочное выражение фильтрации');", true);
            return;
        }

        TaskList.sqlLoadStatment st = new TaskList.sqlLoadStatment();
        st.Lexeme = (sFlt.Length > 0 ? sFlt : "");
        st.EmplID = ctlEmpCombo1.CurrentValue;  
        ListWhere w = new ListWhere();
        w.ListLoadStatment = st;
        ctlCalendar1.Where = w ; 
        ctlCalendar1.DataBind();       
        
    }

    protected string EmplID { get { return ctlEmpCombo1.CurrentValue; } }
         
    protected void btnDaySet_Click(object sender, EventArgs e)
    {
        ctlCalendar1.SetPeriod(TaskCalendar.CalendarPeriod.Day);
    }
   
    protected void btnWeekset_Click(object sender, EventArgs e)
    {
        ctlCalendar1.SetPeriod(TaskCalendar.CalendarPeriod.Week);
    }

    protected void btnMonthSet_Click(object sender, EventArgs e)
    {
        
    }
    
    protected void btnPrev_Click(object sender, EventArgs e)
    {
        ctlCalendar1.MinusTerm();
    }
    
    protected void btnNext_Click(object sender, EventArgs e)
    {
        ctlCalendar1.PlusTerm();
    }

    
  
    protected void cmbEmployeerList_SelectedIndexChanged(object sender, EventArgs e)
    {
        btnFind_Click(null,null);

    }
}
